package com.hluck.mvidemo.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.hluck.mvidemo.data.model.Vertical
import com.hluck.mvidemo.databinding.ItemWallpaperRvBinding

/**
 *
 * @Author： LJH
 * @Time： 2023/10/12
 * @description：
 */
class WallpaperAdapter(private val verticals:ArrayList<Vertical>) :RecyclerView.Adapter<WallpaperAdapter.ViewHolder>() {

    fun addData(data:List<Vertical>){
        verticals.addAll(data)
    }

    class ViewHolder(itemWallpaperRvBinding: ItemWallpaperRvBinding) : RecyclerView.ViewHolder(itemWallpaperRvBinding.root){
        var binding: ItemWallpaperRvBinding = itemWallpaperRvBinding

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(ItemWallpaperRvBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        verticals[position].preview.let {
            Glide.with(holder.itemView.context).load(it).into(holder.binding.ivWallPaper)
        }
    }

    override fun getItemCount(): Int = verticals.size
}